package com.cdc.youthbanner.ui;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.cdc.youthbanner.R;
import com.cdc.youthbanner.adapter.ImageNetAdapter;
import com.cdc.youthbanner.bean.DataBean;
import com.cdc.youthbanner.databinding.BannerBinding;
import com.youth.banner.Banner;
import com.youth.banner.indicator.RectangleIndicator;
import com.youth.banner.util.BannerUtils;


public class BannerFragment extends Fragment {

    private BannerBinding mBinding;

    Banner banner;

    public static Fragment newInstance() {
        return new BannerFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding=BannerBinding.inflate(inflater,container,false);
        View view = mBinding.getRoot();
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mBinding.banner.setAdapter(new ImageNetAdapter(DataBean.getTestData3()));
        mBinding.banner.setIndicator(new RectangleIndicator(getActivity()));
        mBinding.banner.setIndicatorNormalWidth((int) BannerUtils.dp2px(12));
        mBinding.banner.setIndicatorSpace((int) BannerUtils.dp2px(4));
        mBinding.banner.setIndicatorRadius(0);
    }

    @Override
    public void onStart() {
        super.onStart();
        mBinding.banner.start();
    }

    @Override
    public void onStop() {
        super.onStop();
        mBinding.banner.stop();
    }
}
